// home.js
const Controller = require('egg').Controller;

class HomeController extends Controller {
    async index() {
        this.ctx.body = 'Hello World';
    }

    // 测试query传参
    async query() {
        const { ctx } = this;
        ctx.body = {
            message: 'query',
            data: {
                id: ctx.query.id,
                name: ctx.query.name,
            }
        }
    }

    // 测试params传参
    async params() {
        const { ctx } = this;
        ctx.body = {
            message: 'params',
            data: {
                id: ctx.params.id,
                name: ctx.params.name,
            }
        }
    }

    // 测试body传参
    async postdata() {
        const { ctx } = this;
        ctx.body = {
            message: 'postdata',
            data: ctx.request.body
        }
    }

    async testService() {
        const { ctx } = this;
        ctx.body = await ctx.service.testService.test();
    }
}

module.exports = HomeController;